﻿#define _CRT_SECURE_NO_WARNINGS
// ↑ 将本行在代码放在第一行可以避免 scanf的报错问题（仅在VS编译器里）

#include"BinaryTree.h"


//【函数定义】
/*前序遍历*/void PrevOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}
	printf("%d ", root->data);
	PrevOrder(root->left);
	PrevOrder(root->right);

}
/*中序遍历*/void MidOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}
	MidOrder(root->left);
	printf("%d ", root->data);
	MidOrder(root->right);
}
/*后序遍历*/void NextOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}
	NextOrder(root->left);
	NextOrder(root->right);
	printf("%d ", root->data);
}
/*二叉树计算大小*/int TreeSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	else
	{
		return  1 + TreeSize(root->left) + TreeSize(root->right);
	}
}
/*二叉树计算叶子节点数量*/int TreeLeafSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	if (root->left == NULL && root->right == NULL)
	{
		return   1;
	}
	else
	{
		return (TreeLeafSize(root->left) + TreeLeafSize(root->right));
	}
}
/*二叉树计算深度*/int TreeDepth(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	int rd = TreeDepth(root->right);
	int ld = TreeDepth(root->left);
	return rd > ld ? rd + 1 : ld + 1;
}